import request from '@/utils/request'

export function getProductList(data) {
    return request({
        url: '/products' + (data.id ? "/" + data.id : ""),
        method: 'get',
        params: data
    })
}

export function repairpackages(data) {
    return request({
        url: '/packages/patch/repair',
        method: 'post',
        data
    })
}

export function getProductHostsAddList(data) {
    return request({
        url: '/subscribed',
        method: 'get',
        params: data
    })
}

export function getAllPckageNames() {
    return request({
        url: '/packages/allNames',
        method: 'get'
    })
}
export function getPackageVersion({ name }) {
    return request({
        url: `/packages/${name}/versions`,
        method: 'get'
    })
}
export function getProductTypes() {
    return request({
        url: `/products/types`,
        method: 'get'
    })
}
export function addProduct(data) {
    return request({
        url: `/products`,
        method: 'post',
        data
    })
}
export function editProduct({ id, data }) {
    return request({
        url: `/products/${id}`,
        method: 'put',
        data
    })
}
export function getProductPackagesGroup(data, id) {
    return request({
        url: `products/${id}/repositories`,
        method: 'get',
        params: data
    })
}
export function getProductRepoDetail({ id, id2 }) {
    return request({
        url: `products/${id}/repositories/${id2}`,
        method: 'get',
    })
}
export function getProductPackagesList(data) {
    return request({
        url: '/packages/patches',
        method: 'get',
        params: data
    })
}
export function getPackageDetail(id) {
    return request({
        url: `/packages/${id}`,
        method: 'get',
    })
}
export function getRepoSync({ id, ids, ...data }) {
    return request({
        url: `products/${id}/repositories/sync`,
        method: 'post',
        data
    })
}
export function addRepo({ id, data }) {
    return request({
        url: `/products/${id}/repositories`,
        method: 'post',
        data
    })
}
export function deleteProduct({ id, ...data }) {
    return request({
        url: `/products/${id}`,
        method: 'delete',
        params: data
    })
}
export function deleteProductRepo({ id, ...data }) {
    return request({
        url: `/products/${id}/repositories/batchDelete`,
        method: 'delete',
        data
    })
}
export function getProdRepoInfo(data) {
    return request({
        url: `/repositories/list`,
        method: 'get',
        params: data
    })
}
export function importRepo({ id, id2, data }) {
    return request({
        url: `/products/${id}/repositories/${id2}/rpms`,
        method: 'post',
        data
    })
}
export function importCVE({ id, id2, data }) {
    return request({
        url: `/products/${id}/repositories/${id2}/errata`,
        method: 'post',
        data
    })
}
export function getRpmInstallMatch(data) {
    return request({
        url: `/packages/hostMatch`,
        method: 'get',
        params: data

    })
}
export function getRpmInstallBatchMatch(data) {
    return request({
        url: `/packages/batchMatch`,
        method: 'get',
        params: data

    })
}
export function issueRpmHostInstall(data) {
    return request({
        url: `/packages/patch/install?allowDup=false`,
        method: 'post',
        data

    })
}
export function issueRpmBatchUpdate(data) {
    return request({
        url: `/packages/patch/update`,
        method: 'post',
        data
    })
}
export function issueRpmBatchInstall({ data, allowDup }) {
    return request({
        url: `/packages/patch/install?allowDup=${allowDup}`,
        method: 'post',
        data
    })
}
export function issueRpmHostUpdate(data) {
    return request({
        url: `/packages/patch/update`,
        method: 'post',
        data
    })
}
export function issueSpUpgrade({ id, data }) {
    return request({
        url: `sp_upgrade/${id}/run`,
        method: 'post',
        data
    })
}
export function getSPList(data) {
    return request({
        url: `/sp_upgrade/spList`,
        method: 'get',
        params: data
    })
}
export function getLastSP() {
    return request({
        url: `/sp_upgrade/lastSp`,
        method: 'get',
    })
}
export function getAvailableHosts(data, upgradeCheckId) {
    return request({
        url: `/sp_upgrade/checkHosts?upgradeCheckId=${upgradeCheckId}`,
        method: 'get',
        params: data
    })
}
export function getProdRepoList(data, id) {
    return request({
        url: `/packages/${id}/repositories`,
        method: 'get',
        params: data
    })
}
export function getRpmList(data, id) {
    return request({
        url: `/products/1/repositories/${id}/rpms`,
        method: 'get',
        params: data
    })
}
export function deleteRpm({ id, repoId, data }) {
    return request({
        url: `/products/${id}/repositories/${repoId}/rpms/batchDelete`,
        method: 'delete',
        data
    })
}
export function editRepo({ id, repoId, data }) {
    return request({
        url: `/products/${id}/repositories/${repoId}`,
        method: 'put',
        data
    })
}
export function importSP(data) {
    return request({
        url: `/spUpgrade/spUpload`,
        method: 'post',
        data
    })
}
export function getCombine({ ...data }) {
    return request({
        url: `/spUpgrade/combine`,
        method: 'post',
        params: data
    })
}
export function getAllCVE(data) {
    return request({
        url: `/cveAllList`,
        method: 'get',
        params: data
    })
}
export function issueCVE(data) {
    return request({
        url: `/cve/issue`,
        method: 'post',
        data
    })
}
export function exportCVE(data) {
    return request({
        url: `/downloadCve`,
        method: 'post', responseType: 'blob',
        data
    })
}
export function deleteCVE(id) {
    return request({
        url: `/cve/delete/${id}`,
        method: 'get',
    })
}
export function importCVElist(data) {
    return request({
        url: `/products/repositories/errata`,
        method: 'post',
        data
    })
}
export function deleteConfirm(id) {
    return request({
        url: `/cve/delete/confirm/${id}`,
        method: 'get',
    })
}